package net.starelement.gamelib.task;

import cn.nukkit.plugin.PluginBase;
import cn.nukkit.scheduler.PluginTask;
import net.starelement.gamelib.player.PlayerList;

/**  StarElement 倒计时任务类
 *
 * @author Ruok233
 * @since NukkitX API 1.0.9 | StarElement Project v1-alpaca
 *
 * create: 2019/12/14
 */
public abstract class CountdownTask extends PluginTask<PluginBase> {

    private PlayerList list;
    private int time;

    public CountdownTask(PluginBase owner,int time) {
        super(owner);
        this.list = PlayerList.getInstance();
        this.time = time;
    }

    @Override
    public void onRun(int i) {
        list.sendTitle("§b游戏即将开始", ("§a" + time));
        time--;
        if (time == 0) {
            this.cancel();
            start();
        }
    }

    public abstract void start();
}